﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoreDemo.Model;

namespace CoreDome.Services
{
    public class CinemaMemoryService : ICinemaService
    {

        private readonly List<Cinema> _cinemas = new List<Cinema>();
        public CinemaMemoryService()
        {
            _cinemas.Add(new Cinema() {
                Id = 1,
                Name = "万达影院",
                Location = "新港东路万胜围",
                Capacity = 1000
            });
            _cinemas.Add(new Cinema()
            {
                Id = 2,
                Name = "期遇ta影院",
                Location = "黄埔村北帝庙对面",
                Capacity = 500
            });
        }

        public Task AddAsync(Cinema model)
        {
            var maxId = _cinemas.Max(x => x.Id);
            model.Id = maxId+1;
            _cinemas.Add(model);
            return Task.CompletedTask;
        }

        public Task<IEnumerable<Cinema>> GetAllAsync()
        {
            return Task.Run(() =>  _cinemas.AsEnumerable());
        }

        public Task<Cinema> GetByIdAsync(int id)
        {
            return Task.Run(()=>_cinemas.FirstOrDefault(x=>x.Id==id));
        }

        public Task<Sales> GetSalesAsync()
        {
            throw new NotImplementedException();
        }
    }
}
